package edu.sctu.practice.class01.zhoumengxue.assign.assign08.assign08_03;

import java.net.*;
import java.io.*;

/**
 * Created by ASUS on 2015/12/24.
 */
public class Server {
    public static void main(String args[]) {
        DatagramPacket pack = null;
        DatagramSocket mailReceive = null;
        ServerThread thread;
        byte b[] = new byte[8192];
        InetAddress address = null;
        pack = new DatagramPacket(b, b.length);
        while (true) {
            try {
                mailReceive = new DatagramSocket(1234);//创建在端口1234负责收取数据包的DatagramSocket对象。
            } catch (IOException e1) {
                System.out.println("正在等待");
            }
            try {
                mailReceive.receive(pack);
                address = pack.getAddress(); //pack返回InetAddress对象。
                System.out.println("客户的地址:" + address);
            } catch (IOException e) {
            }
            if (address != null) {
                new ServerThread(address).start();
            } else {
                continue;
            }
        }
    }
}

